<template>
  <div class="OutOfReportForm">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span style="line-height: 36px;">出库明细报表</span>
      </div>
      <s-table
        :table="table"
        @http="tableWatch">
        <el-form-item label="选择时间" prop="cjsj">
          <el-date-picker
            v-model="oDate"
            @change="getTime"
            type="daterange"
            placeholder="选择日期范围">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="渠道名称" prop="mc">
          <el-autocomplete
            v-model="Name"
            :fetch-suggestions="querySearchAsync"
            @select="handleSelect"
            placeholder="请输入内容"
          >
          </el-autocomplete>
        </el-form-item>
        <el-form-item slot="multiSelect" label="多选操作" prop="multiSelect" v-if="table.multiSelect">
          <el-row>
            <el-col :span="8">
              <el-button size="small" type="info" @click="tableExport('')">多选导出</el-button>
            </el-col>
          </el-row>
        </el-form-item>
      </s-table>
    </el-card>
  </div>
</template>
<script>
  import {AutoVue} from '~/plugins/Tools';
  import Config from '~/config';
  export default AutoVue({
    name: 'outOperation_c2q1heck-FEcarWms',
    head: {
      'title': '出库明细报表',
      'meta': [
        {'hid': 'description', 'name': 'description', 'content': '乐速科技平台 出库明细报表 查看出库明细报表信息'},
      ],
    },
    store: ['USER'],
    data: {
      header: {
        'Content-Disposition': 'attachment',
      },
      table: {
        column: [
          /* {
            label: '发起部门',
            prop: 'fqbm',
            minWidth: '0px',
            search: false,
          },
          {
            label: '发起人',
            prop: 'fqr',
            minWidth: '0px',
            search: true,
          },
          {
            label: '用途',
            prop: 'yt',
            minWidth: '0px',
            search: false,
          }, */
        ],
        data: [ /* {
          hpbh: '20160502',
          hpmc: '王小虎',
          sl: '1518 弄',
          xbh: '1',
        } */ ],
        key: 'id',
        tableColumn: 0,
        url: '/Outstock/list',
        option: {
          ddqdid: '',
          cjsj_start: '',
          cjsj_end: '',
          ddqdmc: '111',
        },
        total: 0,
      },
      Name: '',
      time: '',
      times: '',
      oDate: '',
      cball: [],
      ddqdmc: '',
    },
    transition: 'slide-fade',
    methods: {
      // 输入后建议
      async querySearchAsync (queryString, callback) {
        let list = [{}];
        let data = await this.post('/Outstock/getDdmc', {
          mc: this.Name,
        });
        for (let i of data) {
          i.value = i.mc;
        }
        list = data;
        callback(list);
      },
      // 输入后建议回调
      handleSelect (data) {
        let ido = data.id;
        let idc = data.mc;
        console.log(data);
        this.table.option.ddqdid = ido;
        this.table.option.ddqdmc = idc;
        this.table.option.cjsj_start = this.time;
        this.table.option.cjsj_end = this.times;
        this.tableWatch('table');
      },
      getTime (date) {
        let Adate = new Date(date.substring(0, 10));
        this.time = Adate.getTime();
        let Bdate = new Date(date.substr(13, 10));
        this.times = Bdate.getTime();
        this.table.option.cjsj_start = this.time;
        this.table.option.cjsj_end = this.times;
      },
      tableExport (row) {
        let tableRef = 'table';
        let ids = [];
        if (row) {
          ids.push(row.id);
        } else {
          this[tableRef].multipleSelection.forEach(item => {
            ids.push(item.cpid);
          });
        }
        this.$confirm('您将导出出库明细报表数据。', '确认导出？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(async _ => {
            try {
              let option = Object.assign({}, this['autoVue_' + tableRef]);
              await this.p({
                url: '/Outstock/OutstockExport',
                method: 'post',
                responseType: 'blob',
                data: {
                  cjsj_end: this.times,
                  cjsj_start: this.time,
                  ddqdid: this.table.option.ddqdid,
                  ids,
                  page: 1,
                  rows: 10,
                },
              });
            } catch (err) {
              console.log(err);
            }
          })
          .catch(_ => {
          });
      },
    },
    mounted: async function () {
      try {
        let headdata = await this.post('/Outstock/listHeader');
        this.table.tableColumn = headdata.column;
        this.table.tableColumnAll = headdata.column;
        this.Name = '';
        this.oDate = '';
        this.table.data = [];
      } catch (err) {
        console.log(err);
      }
    },
  });
</script>
<style scoped lang="scss">
  .box-card {
    margin: 20px;
  }
  .createTimeSpan {
    display: block;
    margin-top: 34px;
  }
  @media screen and (max-width: 800px) {
    .createTimeSpan {
      margin-top: 0;
    }
    .box-card {
      margin: 0;
    }
  }

  .el-select {
    width: 100%;
  }
  .headertype {
    color:#1bab8b;
  }
</style>

<style lang="scss">

</style>
